<style lang="less" scoped>
  .div-height {
    line-height: 38px;
  }

  .f-w70 {
    width: 70% !important;
  }

  .f-w50 {
    width: 50% !important;
  }

  .f-w80 {
    width: 80% !important;
  }

  .f-w25 {
    width: 20% !important;
  }
</style>
<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content f-bs1 div-height">
          <label class="f-ml10 f-mr10">运价文件编号：</label>
          <label class="f-ml10 f-mr10">{{freightContractDetailData.contractNumber}}</label>
          <label class="f-ml10 f-mr10">[ {{freightContractDetailData.statusName}} ]</label>
          <label class="f-fr f-ml10 f-mr10">{{freightContractDetailData.createDate}}</label>
          <label class="f-fr f-mr10 f-ml10">[ {{freightContractDetailData.createUserName}} ]</label>
        </div>
      </el-col>
    </el-row>
    <el-row class="f-mt10 f-bs1">
      <el-col :span="24">
        <div class="grid-content div-height f-bbs1">
          <label class="f-ml10 f-mr10"> 基本信息 </label>
        </div>
        <div class="grid-content">
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label class="f-ml10">运价合同名称:</label>
              <label>{{freightContractDetailData.name}}</label>
            </div>
          </el-col>
          <el-col :span="8" class="div-height">
            <div class="grid-content">
              <label>签约方:</label>
              <label>{{freightContractDetailData.signatoryName}}</label>
            </div>
          </el-col>
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label>合同组织:</label>
              <label>{{freightContractDetailData.contractOrganizationName}}</label>
            </div>
          </el-col>
        </div>
        <div class="grid-content">
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label class="f-ml10">结算方式:</label>
              <label>{{freightContractDetailData.paymentTypeName}}</label>
            </div>
          </el-col>
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label>生效时间:</label>
              <label>{{freightContractDetailData.operativeDate}}</label>
            </div>
          </el-col>
          <el-col :span="8" class="div-height">
            <div class="grid-content">
              <label>失效时间:</label>
              <label>{{freightContractDetailData.loseEfficacyDate}}</label>
            </div>
          </el-col>
        </div>
        <div class="grid-content">
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label class="f-ml10">备注:</label>
              <label>{{freightContractDetailData.remark}}</label>
            </div>
          </el-col>
        </div>
        <div class="grid-content">
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label class="f-ml10">发票抬头:</label>
              <label>{{freightContractDetailData.taxsheetTitleName}}</label>
            </div>
          </el-col>
        </div>
        <div class="grid-content">
          <el-col :span="8" class="div-height">
            <div class="grid-content bg-purple">
              <label class="f-ml10">发票类型:</label>
              <label>{{freightContractDetailData.invoiceName}}</label>
            </div>
          </el-col>
        </div>
      </el-col>
    </el-row>
    <el-row class="f-mt10">
      <el-col :span="12" class="f-bs1">
        <div class="grid-content">
          <div>
            <div class="f-mt f-wa">
              <el-button type="primary" class="f-wa f-ml10 f-mt10 f-mb10"
                         v-if="freightContractDetailData.status === 112001001"
                         @click="createFreightContractDetailDialog">新增
              </el-button>
            </div>
          </div>
          <el-table :data="freightContractLinesTableData" highlight-current-row border @row-click="rowClick">
            <el-table-column label="序号" type="index">
            </el-table-column>
            <el-table-column prop="ageingTypeName" label="始发地">
              <template slot-scope="scope">
                {{scope.row.startProvinceNmae}}{{scope.row.startCityName}}{{scope.row.startCountyName}}
              </template>
            </el-table-column>
            <el-table-column prop="ageingScope" label="目的地">
              <template slot-scope="scope">
                {{scope.row.endProvinceNmae}}{{scope.row.endCityName}}{{scope.row.endCountyName}}
              </template>
            </el-table-column>
            <el-table-column prop="agingScope" label="时效" width="80">
            </el-table-column>
            <el-table-column prop="startToll" label="起步收费" width="100">
            </el-table-column>
            <el-table-column prop="remark" label="备注">
            </el-table-column>
            <el-table-column prop="operation" label="操作" width="200">
              <template slot-scope="scope">
                <el-button  type="primary" v-if="freightContractDetailData.status === 112001001"
                           @click="modifyFreightContractDetailDialog(scope.row)">修改
                </el-button>
                <el-button  type="primary" v-if="freightContractDetailData.status === 112001001"
                           @click="deleteFreightContractLine(scope.row.id)">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <!--分页工具条-->
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="currentPage"
              :page-size="pageSize"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total,sizes,prev, pager, next, jumper"
              :total="total" style="float: right">
            </el-pagination>
          </el-col>

          <el-dialog :title="freightContractDetailFormTitle" :visible.sync="freightContractDetailFormDialog" size="tiny">
            <el-form label-width="100px" ref="freightContractDetailForm" :model="freightContractDetailForm">
              <el-form-item label="始发地" prop="startAddress"
                            :rules="[{required: true,type: 'array', message: '请选择始发地', trigger: 'change'}]">
                <address-select v-model="freightContractDetailForm.startAddress"
                                placeholder="请选择始发地"
                                change-on-select
                                class="f-w233 f-w50">
                </address-select>
              </el-form-item>
              <el-form-item label="目的地" prop="endAddress"
                            :rules="[{required: true,type: 'array', message: '请选择目的地', trigger: 'change'}]">
                <address-select v-model="freightContractDetailForm.endAddress"
                                placeholder="请选择始发地"
                                change-on-select
                                class="f-w233 f-w50">
                </address-select>
              </el-form-item>
              <el-form-item label="时效范围" prop="agingScope"
                            :rules="[{required: true, message: '请输入时效范围', trigger: 'change'}]">
                <el-input v-model="freightContractDetailForm.agingScope" class="f-w50"
                          placeholder="请输入时效范围费"></el-input>
              </el-form-item>
              <el-form-item label="起步收费" prop="startToll">
                <el-input type="number" v-model.number="freightContractDetailForm.startToll" class="f-w50"
                          placeholder="请输入起步收费"></el-input>
              </el-form-item>
              <el-form-item label=" 备 注 " prop="remark">
                <el-input type="textarea" v-model="freightContractDetailForm.remark" class="f-w50"
                          auto-complete="off"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="freightContractDetailFormDialog = false">
                取 消
              </el-button>
              <el-button type="primary"
                         @click="createFreightContractDetail">确 定
              </el-button>
            </div>
          </el-dialog>
        </div>
      </el-col>
      <!--线路详情部分-->
      <el-col :span="11" class="f-ml10 f-bs1">
        <div class="grid-content">
          <el-tabs @tab-click="tabsClick" v-model="tabsName">
            <el-tab-pane label="重货" name="112003001">
              <div>
                <div class="f-mt f-wa">
                  <el-button type="primary" class="f-wa f-ml10 f-mb10"
                             v-if="freightContractDetailData.status === 112001001"
                             @click="savesaveContractLineDetailFun(112003001,'重货')">新增
                  </el-button>
                </div>
              </div>
              <el-row v-for="(freightContractDetail,index) in freightContractDetailList"
                      v-if="freightContractDetail.billingType===112003001" :key="index">
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">货物类型：
                    <el-input v-model="freightContractDetail.cargoTypeName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">货物名称：
                    <el-input v-model="freightContractDetail.cargoName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">包装形式：
                    <el-input v-model="freightContractDetail.packTypeName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple">
                    <!--<el-button type="primary" class="f-wa f-ml10 f-mt10 f-mb10"-->
                    <!--@click="modifyFreightContractDetail(freightContractDetail)">修改-->
                    <!--</el-button>-->
                    <el-button type="primary" class="f-wa f-ml10 f-mt10 f-mb10"
                               @click="deleteFreightContractDetail(freightContractDetail.ids)">删除
                    </el-button>
                  </div>
                </el-col>
                <el-col :span="24" v-if="freightContractDetail.trunkLineType === 112010001">
                  <div class="grid-content bg-purple-dark">
                    <el-table :data="freightContractDetail.zhGradeds" highlight-current-row border>
                      <el-table-column prop="startGraded" label="阶梯起始（吨）">
                      </el-table-column>
                      <el-table-column prop="endGraded" label="阶梯终止（吨）">
                      </el-table-column>
                      <el-table-column prop="billingUnivalence" label="价格（元/吨）">
                      </el-table-column>
                    </el-table>
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        上门提货费：
                        <el-input v-model="freightContractDetail.extractMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.extractShortBillingUnit"></label>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        送货上门费：
                        <el-input v-model="freightContractDetail.sendMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.sendShortBillingUnit"></label>
                      </div>
                    </el-col>
                  </div>
                </el-col>
                <el-col
                  v-if="freightContractDetail.trunkLineType === 112010002||freightContractDetail.trunkLineType === 112010003">
                  <div class="grid-content bg-purple f-mt10 f-mb10">干线价格：
                    <el-input v-model="freightContractDetail.cargoName" style="width: 12.5%"
                              :disabled="true"></el-input>
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <label v-html="freightContractDetail.trunkLineTypeName"></label>：
                    <el-input v-model="freightContractDetail.billingUnivalence" style="width: 12.5%"
                              :disabled="true"></el-input>
                    元/吨
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        上门提货费：
                        <el-input v-model="freightContractDetail.extractMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.extractShortBillingUnit"></label>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        送货上门费：
                        <el-input v-model="freightContractDetail.sendMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.sendShortBillingUnit"></label>
                      </div>
                    </el-col>
                  </div>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="抛货" name="112003002">
              <div>
                <div class="f-mt f-wa">
                  <el-button v-if="freightContractDetailData.status === 112001001" type="primary"
                             class="f-wa f-ml10 f-mb10"
                             @click="savesaveContractLineDetailFun(112003002,'抛货')">新增
                  </el-button>
                </div>
              </div>
              <el-row v-for="(freightContractDetail,index) in freightContractDetailList"
                      v-if="freightContractDetail.billingType===112003002" :key="index">
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">货物类型：
                    <el-input v-model="freightContractDetail.cargoTypeName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">货物名称：
                    <el-input v-model="freightContractDetail.cargoName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple f-mt10 f-mb10">包装形式：
                    <el-input v-model="freightContractDetail.packTypeName" class="f-w50"
                              :disabled="true"></el-input>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="grid-content bg-purple">
                    <el-button type="primary" class="f-wa f-ml10 f-mt10 f-mb10"
                               @click="deleteFreightContractDetail(freightContractDetail.ids)">删除
                    </el-button>
                  </div>
                </el-col>
                <el-col :span="24" v-if="freightContractDetail.trunkLineType === 112010001">
                  <div class="grid-content bg-purple-dark">
                    <el-table :data="freightContractDetail.phGradeds" highlight-current-row border>
                      <el-table-column prop="startGraded" label="阶梯起始（吨）">
                      </el-table-column>
                      <el-table-column prop="endGraded" label="阶梯终止（吨）">
                      </el-table-column>
                      <el-table-column prop="billingUnivalence" label="价格（元/吨）">
                      </el-table-column>
                    </el-table>
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        上门提货费：
                        <el-input v-model="freightContractDetail.extractMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.extractShortBillingUnit"></label>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        送货上门费：
                        <el-input v-model="freightContractDetail.sendMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.sendShortBillingUnit"></label>
                      </div>
                    </el-col>
                  </div>
                </el-col>
                <el-col
                  v-if="freightContractDetail.trunkLineType === 112010002||freightContractDetail.trunkLineType === 112010003">
                  <div class="grid-content bg-purple f-mt10 f-mb10">干线价格：
                    <el-input v-model="freightContractDetail.cargoName" style="width: 12.5%"
                              :disabled="true"></el-input>
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <label v-html="freightContractDetail.trunkLineTypeName"></label>：
                    <el-input v-model="freightContractDetail.billingUnivalence" style="width: 12.5%"
                              :disabled="true"></el-input>
                    元/吨
                  </div>
                  <div class="grid-content bg-purple f-mt10 f-mb10">
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        上门提货费：
                        <el-input v-model="freightContractDetail.extractMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.extractShortBillingUnit"></label>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="grid-content f-bbs1 f-pb10">
                        送货上门费：
                        <el-input v-model="freightContractDetail.sendMoney" style="width: 21%"
                                  :disabled="true"></el-input>
                        <label v-html="freightContractDetail.sendShortBillingUnit"></label>
                      </div>
                    </el-col>
                  </div>
                </el-col>
              </el-row>

            </el-tab-pane>
          </el-tabs>
          <el-dialog title="新增线路详情文件" :visible.sync="saveContractLineDetailDialog" size="tiny">
            <el-form label-width="100px" ref="freightContractLineDetailForm" :model="freightContractLineDetailForm">
              <el-form-item label="货物类型" prop="startGraded">
                <el-select v-model="freightContractLineDetailForm.cargoType" class="f-w80"
                           filterable placeholder="请选择货物包装">
                  <el-option v-for="(cargoType,index) in cargoTypes"
                             :label="cargoType.cnDictValname"
                             :value="cargoType.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="货物品名" prop="endGraded">
                <el-input v-model="freightContractLineDetailForm.cargoName"
                          class="f-w80"></el-input>
              </el-form-item>
              <el-form-item label="包装形式" prop="billingUnivalence">
                <el-select v-model="freightContractLineDetailForm.packType" class="f-w80"
                           filterable placeholder="请选择货物包装">
                  <el-option v-for="(packType,index) in $store.getters.PACKAGE_TYPE"
                             :label="packType.cnDictValname"
                             :value="packType.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="干线价格" prop="contractLineDetailradio"
                            :rules="[{required: true,type:'number',message: '请选择干线价格', trigger: 'change'}]">
                <template>
                  <el-radio-group v-model="freightContractLineDetailForm.contractLineDetailradio"
                                  @change="contractLineDetailradioChange">
                    <el-radio class="radio" :label=112010001>阶梯单价</el-radio>
                    <el-radio class="radio" :label=112010002>一口单价</el-radio>
                    <el-radio class="radio" :label=112010003>一口总价</el-radio>
                  </el-radio-group>
                </template>
                <template>
                  <el-col v-if="freightContractLineDetailForm.contractLineDetailradio === 112010001">
                    <el-form-item v-for="(domain, index) in freightContractLineDetailForm.domains"
                                  :key="domain.key"
                                  :prop="'domains.' + index + '.billingUnivalence'">
                      <el-input v-model="domain.startGraded" class="f-w25" placeholder="起"></el-input>
                      <el-input v-model="domain.endGraded" class="f-w25" placeholder="止"></el-input>
                      <el-input v-model="domain.billingUnivalence" class="f-w25" placeholder="单价"></el-input>
                      <el-button @click.prevent="removeDomain(domain)">删除</el-button>
                    </el-form-item>
                  </el-col>
                  <el-col v-if="freightContractLineDetailForm.contractLineDetailradio === 112010002">
                    一口单价（每票订单）：
                    <el-input type="number" step="0.01" v-model.number="freightContractLineDetailForm.billingUnivalence"
                              class="f-w25"></el-input>
                  </el-col>
                  <el-col v-if="freightContractLineDetailForm.contractLineDetailradio === 112010003">
                    一口总价（每票订单）：
                    <el-input type="number" step="0.01" v-model.number="freightContractLineDetailForm.billingUnivalence"
                              class="f-w25"></el-input>
                  </el-col>
                </template>
              </el-form-item>
              <el-form-item label="上门提货费" prop="extractMoney">
                <el-input type="number" v-model.number="freightContractLineDetailForm.extractMoney"
                          :disabled="freightContractLineDetailForm.extractStart ===112011001"
                          class="f-w50"></el-input>
                <el-checkbox-group v-model="freightContractLineDetailForm.extractStart">
                  <el-checkbox :false-label="0" :true-label="112011001">按始发地应用</el-checkbox>
                </el-checkbox-group>
                <el-radio-group v-model="freightContractLineDetailForm.extractShortBillingUnit">
                  <el-radio class="radio" :disabled="freightContractLineDetailForm.extractStart ===112011001"
                            label="112013001">每票订单（元）
                  </el-radio>
                  <el-radio class="radio" :disabled="freightContractLineDetailForm.extractStart ===112011001"
                            label="112013002">每货量单位（元/吨）
                  </el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="送货上门费" prop="sendMoney">
                <el-input type="number" v-model.number="freightContractLineDetailForm.sendMoney"
                          :disabled="freightContractLineDetailForm.sendStart ===112011002"
                          class="f-w50"></el-input>
                <el-checkbox-group v-model="freightContractLineDetailForm.sendStart">
                  <el-checkbox :false-label="0" :true-label="112011002">按目的地应用</el-checkbox>
                </el-checkbox-group>
                <el-radio-group v-model="freightContractLineDetailForm.sendShortBillingUnit">
                  <el-radio class="radio" :disabled="freightContractLineDetailForm.sendStart ===112011002"
                            label="112013001">每票订单（元）
                  </el-radio>
                  <el-radio class="radio" :disabled="freightContractLineDetailForm.sendStart ===112011002"
                            label="112013002">每货量单位（元/吨）
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="addDomain">新增行</el-button>
              <el-button @click="saveContractLineDetailDialog = false">取 消</el-button>
              <el-button type="primary" @click="saveContractLineDetailClick">确 定</el-button>
            </div>
          </el-dialog>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  getFreightContract,
  saveFreightContractLine,
  searchFreightContractLines,
  deleteFreightContractLine,
  saveFreightContractLineDetail,
  searchFreightContractLineDetails,
  deleteFreightContractLineDetail
} from '../../api/freight/freightContractApi.js';
import { isEmpty, getSelectObect } from '../../lib/util.js';
export default {
  data () {
    return {
      id: this.$route.params.id,
      heavyFreightContractDetailTableData: [],
      gentlyFreightContractDetailTableData: [],
      gentlyCargoTypes: [],
      heavyCargoTypes: [],
      gradedHtml: '',
      freightContractDetailData: {},
      lineId: '',
      cargoTypes: [],
      freightContractDetailList: [],
      freightContractDetailFormTitle: '',
      freightContractDetailForm: {
        startAddress: [],
        endAddress: [],
        startProvinceId: '',
        startCityId: '',
        startCountyId: '',
        endProvinceId: '',
        endCityId: '',
        endCountyId: '',
        agingScope: '',
        startToll: '',
        remark: ''
      },
      freightContractDetailFormDialog: false,
      saveContractLineDetailDialog: false,
      freightContractLinesTableData: [],
      tabsName: '112003001',
      freightContractLineDetailForm: {
        domains: [{
          startGraded: '',
          endGraded: '',
          billingUnivalence: ''
        }],
        freightContractLineId: '',
        cargoName: '',
        cargoType: '',
        cargoTypeName: '',
        packType: '',
        packTypeName: '',
        trunkLineType: '',
        trunkLineTypeName: '',
        billingType: '',
        billingTypeName: '',
        startGraded: '',
        endGraded: '',
        billingUnivalence: '',
        sorts: '',
        extractMoney: '',
        extractStart: '',
        extractStartName: '',
        extractShortBillingUnit: '',
        sendMoney: '',
        sendStart: '',
        sendStartName: '',
        sendShortBillingUnit: '',
        remark: '',
        contractLineDetailradio: ''
      },
      contractLineDetails: [],
      lcHtml: {
        jtjgHeavyCargoTypeHtml: '',
        jtjgHeavyCargoNameHtml: '',
        jtjgHeavyPackTypeHtml: '',
        jtjgGentlyCargoTypeHtml: '',
        jtjgGentlyCargoNameHtml: '',
        jtjgGentlyPackTypeHtml: ''
      },
      total: 0,
      currentPage: 1,
      pageSize: 10
    };
  },
  methods: {
    contractLineDetailradioChange (val) {
      this.freightContractLineDetailForm.trunkLineType = val;
    },
    saveContractLineDetailClick () {
      let bo = false;
      if (isEmpty(this.freightContractLineDetailForm.cargoType) && this.freightContractDetailList.length > 0) {
        for (let fcd in this.freightContractDetailList) {
          if (isEmpty(this.freightContractDetailList[fcd].cargoType)) {
            bo = true;
            this.$message.error(this.freightContractDetailList[fcd].billingTypeName + '已经存在货物类型为空的数据，无法新增多条类型为空的数据');
            break;
          }
        }
      }
      if (bo) {
        return;
      }
      this.setContractLineDetailByTrunkLineType();
      this.$refs['freightContractLineDetailForm'].validate((valid) => {
        if (valid) {
          saveFreightContractLineDetail(this.freightContractLineDetailForm).then((res) => {
            if (res.data.successFlg) {
              this.saveContractLineDetailDialog = false;
              this.rowClick({id: this.lineId});
              this.$message.success('新增成功');
            }
          }).catch(function (error) {
            this.$message.error('新增失败');
            console.log(error);
          });
        }
      });
    },
    setContractLineDetailByTrunkLineType () {
      this.contractLineDetails = [];
      let cargoTypeName = getSelectObect(this.freightContractLineDetailForm.cargoType, 'dictVal', this.$store.getters.GOODS_TYPE);
      let packTypeName = getSelectObect(this.freightContractLineDetailForm.packType, 'dictVal', this.$store.getters.PACKAGE_TYPE);
      this.freightContractLineDetailForm.freightContractLineId = this.lineId;
      this.freightContractLineDetailForm.cargoTypeName = isEmpty(cargoTypeName) ? '' : cargoTypeName.cnDictValname;
      this.freightContractLineDetailForm.packTypeName = isEmpty(packTypeName) ? '' : packTypeName.cnDictValname;
    },
    removeDomain (item) {
      var index = this.freightContractLineDetailForm.domains.indexOf(item);
      if (index !== -1) {
        this.freightContractLineDetailForm.domains.splice(index, 1);
      }
    },
    addDomain () {
      this.freightContractLineDetailForm.domains.push({
        value: '',
        key: Date.now()
      });
    },
    rowClick (row) {
      this.lineId = row.id;
      let filters = 'freightContractLineId=' + row.id;
      searchFreightContractLineDetails({
        filters: filters,
        sorts: '-createDate',
        page: 1,
        size: 99
      }).then((res) => {
        if (res.data.successFlg) {
          this.heavyFreightContractDetailTableData = [];
          this.gentlyFreightContractDetailTableData = [];
          this.gentlyCargoTypes = res.data.obj.gentlyCargoTypes;
          this.heavyCargoTypes = res.data.obj.heavyCargoTypes;
          this.freightContractDetailList = res.data.detailModelList;
        }
      });
    },
    deleteFreightContractDetail (id) {
      deleteFreightContractLineDetail(id).then((res) => {
        if (res.data.successFlg) {
          this.$message.success('删除成功');
          this.rowClick({id: this.lineId});
        } else {
          this.$message.error(res.data.errorMsg);
        }
      }).catch(function (error) {
        this.$message.error('删除失败');
        console.log(error);
      });
    },
    modifyFreightContractDetail (row) {
      this.saveContractLineDetailDialog = true;
      this.freightContractLineDetailForm = Object.assign({
        domains: [{
          startGraded: '',
          endGraded: '',
          billingUnivalence: ''
        }],
        freightContractLineId: '',
        cargoName: '',
        cargoType: '',
        cargoTypeName: '',
        packType: '',
        packTypeName: '',
        trunkLineType: '',
        trunkLineTypeName: '',
        billingType: '',
        billingTypeName: '',
        startGraded: '',
        endGraded: '',
        billingUnivalence: '',
        sorts: '',
        extractMoney: '',
        extractStart: '',
        extractStartName: '',
        extractShortBillingUnit: '',
        sendMoney: '',
        sendStart: '',
        sendStartName: '',
        sendShortBillingUnit: '',
        remark: ''
      }, row);
      console.log(row);
    },
    savesaveContractLineDetailFun (val, typeName) {
      this.cargoTypes = [];
      if (val === 112003001) {
        let gentlyArray = [];
        gentlyArray = Object.assign([], this.$store.getters.GOODS_TYPE);
        for (let i = 0; i < gentlyArray.length; i++) {
          if (this.heavyCargoTypes.indexOf(gentlyArray[i].dictVal) !== -1) {
            gentlyArray.splice(i, 1);
            i--;
          }
        }
        this.cargoTypes = gentlyArray;
      } else if (val === 112003002) {
        let heavyArray = [];
        heavyArray = Object.assign([], this.$store.getters.GOODS_TYPE);
        for (let i = 0; i < heavyArray.length; i++) {
          if (this.gentlyCargoTypes.indexOf(heavyArray[i].dictVal) !== -1) {
            heavyArray.splice(i, 1);
            i--;
          }
        }
        this.cargoTypes = heavyArray;
      }
      if (isEmpty(this.lineId)) {
        return this.$message.error('请选择线路文件');
      }

      this.contractLineDetailradio = '';
      if (this.$refs.freightContractLineDetailForm) {
        this.$refs.freightContractLineDetailForm.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.freightContractLineDetailForm) {
        if (this.freightContractLineDetailForm[p] instanceof Array) {
          this.freightContractLineDetailForm[p] = [];
        } else {
          this.freightContractLineDetailForm[p] = null;
        }
      }
      this.freightContractLineDetailForm.billingType = val;
      this.freightContractLineDetailForm.billingTypeName = typeName;
      this.saveContractLineDetailDialog = true;
    },
    deleteFreightContractLine (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        type: 'error'
      }).then(() => {
        deleteFreightContractLine(id).then((res) => {
          if (res.data.successFlg) {
            this.$message.success('删除成功');
            this.searchFreightContractLines('freightContractId=' + this.id);
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          this.$message.error('删除失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    modifyFreightContractDetailDialog (row) {
      this.freightContractDetailFormTitle = '修改';
      this.freightContractDetailFormDialog = true;
      if (this.$refs.freightContractDetailForm) {
        this.$refs.freightContractDetailForm.resetFields();
      }
      for (let p in this.freightContractDetailForm) {
        if (this.freightContractDetailForm[p] instanceof Array) {
          this.freightContractDetailForm[p] = [];
        } else {
          this.freightContractDetailForm[p] = null;
        }
      }
      this.freightContractDetailForm = Object.assign({
        startAddress: [],
        endAddress: [],
        startProvinceId: '',
        startCityId: '',
        startCountyId: '',
        endProvinceId: '',
        endCityId: '',
        endCountyId: '',
        agingScope: '',
        startToll: '',
        remark: ''
      }, row);
    },
    createFreightContractDetailDialog () {
      this.freightContractDetailFormTitle = '新增';
      this.freightContractDetailFormDialog = true;
      if (this.$refs.freightContractDetailForm) {
        this.$refs.freightContractDetailForm.resetFields();
      }
      for (let p in this.freightContractDetailForm) {
        if (this.freightContractDetailForm[p] instanceof Array) {
          this.freightContractDetailForm[p] = [];
        } else {
          this.freightContractDetailForm[p] = null;
        }
      }
    },
    tabsClick (tab, event) {
    },
    createFreightContractDetail () {
      this.freightContractDetailForm.freightContractId = this.id;
      this.setAddress(this.freightContractDetailForm.startAddress, this.freightContractDetailForm.endAddress);
      this.$refs['freightContractDetailForm'].validate((valid) => {
        if (valid) {
          saveFreightContractLine(this.freightContractDetailForm).then((res) => {
            if (res.data.successFlg) {
              this.freightContractDetailFormDialog = false;
              this.$message.success('新增成功');
              this.searchFreightContractLines('freightContractId=' + this.id + ' g0;');
            }
          }).catch(function (error) {
            this.$message.error('新增失败');
            console.log(error);
          });
        }
      });
    },
    setAddress (startAddress, endAddress) {
      this.freightContractDetailForm.startProvinceId = startAddress[0];
      this.freightContractDetailForm.startCityId = startAddress[1];
      this.freightContractDetailForm.startCountyId = startAddress[2];

      this.freightContractDetailForm.endProvinceId = endAddress[0];
      this.freightContractDetailForm.endCityId = endAddress[1];
      this.freightContractDetailForm.endCountyId = endAddress[2];
    },
    getFreightContract (id) {
      getFreightContract(id).then((res) => {
        if (res.data.successFlg) {
          this.freightContractDetailData = res.data.obj;
        }
      });
    },
    searchFreightContractLines (filters) {
      searchFreightContractLines({
        filters: filters,
        sorts: '-createDate',
        page: this.currentPage,
        size: this.pageSize
      }).then((res) => {
        if (res.data.successFlg) {
          this.freightContractLinesTableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
        }
      });
    },

    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.getFreightBases('freightFileId=' + this.id + ' g0;');
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.getFreightBases('freightFileId=' + this.id + ' g0;');
    }
  },
  // 初始化数据
  mounted () {
    //      this.addDomain();
    this.getFreightContract(this.id);
    this.searchFreightContractLines('freightContractId=' + this.id);
    this.$store.commit('initDict');
  }
};
</script>
